<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${servicePackageName}.mapper.sys.SysUserMapper">

<select id="getUserListPage" parameterType="${servicePackageName}.qo.sys.UserListPageReq"  resultType="${servicePackageName}.vo.sys.UserListPageVo">
<#noparse>
	SELECT
		t1.id,t1.user_account AS userAccount,t1.user_name AS userName,t1.is_enable AS isEnable,
		(SELECT GROUP_CONCAT(t3.role_name) FROM sys_user_role t2 LEFT JOIN sys_role t3 ON t2.role_id = t3.id WHERE t2.user_id = t1.id) AS roleName,
		(SELECT GROUP_CONCAT(t3.department_name) FROM sys_user_department t2 LEFT JOIN sys_department t3 ON t2.department_id = t3.id WHERE t2.user_id = t1.id) AS depName
	FROM
		sys_user t1
		WHERE t1.is_delete = 0
	<if test="param.userAccount != null and param.userAccount != ''">
        		AND LOCATE(#{param.userAccount},t1.user_account) 
    </if>
    <if test="param.userName != null and param.userName != ''">
        		AND LOCATE(#{param.userName},t1.user_name) 
    </if>
        <if test="param.departmentId != null and param.departmentId != 0">
        		AND t1.id IN (SELECT user_id FROM sys_user_department WHERE department_id = #{param.departmentId})
    </if>
    </#noparse>
	</select>
	
		<select id="getUserInfo"  resultType="${servicePackageName}.vo.sys.UserListPageVo">
		<#noparse>
		SELECT
		t1.id,t1.user_account AS userAccount,t1.user_name AS userName,t1.is_enable AS isEnable,
		(SELECT GROUP_CONCAT(t3.role_name) FROM sys_user_role t2 LEFT JOIN sys_role t3 ON t2.role_id = t3.id WHERE t2.user_id = t1.id) AS roleName,
		(SELECT GROUP_CONCAT(t3.id) FROM sys_user_role t2 LEFT JOIN sys_role t3 ON t2.role_id = t3.id WHERE t2.user_id = t1.id) AS roleIdStr,
		(SELECT GROUP_CONCAT(t3.department_name) FROM sys_user_department t2 LEFT JOIN sys_department t3 ON t2.department_id = t3.id WHERE t2.user_id = t1.id) AS depName
		
	FROM
		sys_user t1
		WHERE t1.id = #{userId}
</#noparse>
	</select>
	
	
</mapper>
